#include "stm32f1xx.h" 

#define PERIODIC(T) \
    static uint32_t nxt = 0; \
    if (HAL_GetTick() < nxt) return; \
    nxt += (T); \
    if (nxt > 1000) nxt = 0; //防止溢出

#define PERIODIC_START(NAME, T) \
    static uint32_t NAME##_nxt = 0; \
    if (HAL_GetTick() >= NAME##_nxt) {\
        NAME##_nxt += (T); \
        if (NAME##_nxt > 1000) NAME##_nxt = 0; //防止溢出
#define PERIODIC_END() \
    } else return;
    